//
//  ViewController.h
//  Regatta Mapping
//
//  Created by Asif on 8/4/12.
//  Copyright (c) 2012 TopOfStack Software. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import "settingView.h"
#import "Category.h"
#import "XMLReader.h"
#import "RaceLimitLocation.h"
#import "MarkBoatLocation.h"
#import "RaceBoatAnnotation.h"
#import "message_header.h"

@class RaceLimitLocation;
@class MarkBoatLocation;

@interface ViewController : UIViewController<MKMapViewDelegate, UIPopoverControllerDelegate, UITextViewDelegate, NSStreamDelegate, UIAlertViewDelegate>
{
    @public UIPopoverController *pop;
    
    @public UIPopoverController *pop2;
    
    IBOutlet MKMapView* myMapView;
    
    // the data representing the racecourse polygon 
    MKPolygon* raceLimitPolygon;
	
    
	// the view we create for the polygon on the map
    MKPolygonView* raceLimitPolygonView;
	
	// the rect that bounds the loaded points
	MKMapRect routeRect;
    
    IBOutlet UITextView* chatView;
    
    
    NSDictionary* regattaDictionary;
    NSDictionary* raceDictionary;
    NSDictionary* boatDictionary;
    
    NSInputStream	*inputStream;
	NSOutputStream	*outputStream;    
    NSMutableData* serverReturnedData;
    
    //for incoming messages from server//
    NSMutableData *messageHeader;
    NSMutableData *messageBody;
    NSMutableData *messageCRC;    
    int expecting;
    int needMore;
    
    
    NSMutableArray* markAnnotationArray;
    NSMutableArray* raceLimitAnnotationArray;
    
    NSMutableArray* racingBoatsArray;
    NSMutableDictionary* raceBoatAnnotationDictionary;
    
    NSTimer* reconnectTimer;
    
    UIAlertView* noConnectionAlert;
    
    
}

@property (nonatomic, retain) MKMapView* myMapView;
@property (nonatomic, retain) MKPolygon* raceLimitPolygon;
@property (nonatomic, retain) MKPolygonView* raceLimitPolygonView;

@property (nonatomic, retain) UITextView* chatView;

@property (nonatomic, retain) NSDictionary* regattaDictionary;
@property (nonatomic, retain) NSDictionary* raceDictionary;
@property (nonatomic, retain) NSDictionary* boatDictionary;

@property (nonatomic, retain) NSInputStream *inputStream;
@property (nonatomic, retain) NSOutputStream *outputStream;
@property (nonatomic, retain)  NSMutableData* serverReturnedData;

@property (nonatomic, retain) NSMutableArray* markAnnotationArray;
@property (nonatomic, retain) NSMutableArray* raceLimitAnnotationArray;

@property (nonatomic, retain) NSMutableArray* racingBoatsArray;
@property (nonatomic, retain) NSMutableDictionary* raceBoatAnnotationDictionary;


-(IBAction)clearChatWindow;
-(IBAction)loadSettings;
-(IBAction)loadCategory;
-(IBAction)zoomIn;
-(IBAction)zoomOut;

-(void) initNetWorkCommunicationWithIP:(NSString*)IP Port:(int) port;
-(void) updateChatWindow:(NSString*)chatText;
-(void) setupMap;
-(void) reconnect;
-(void) updateMap:(MKMapType)mapType;

@end
